package com.itany.shop.service.proxy;

import com.itany.shop.entity.Product;
import com.itany.shop.factory.ObjectFactory;
import com.itany.shop.service.ProductService;
import com.itany.shop.tran.TransactionManager;
import com.itany.shop.util.PageInfo;

import java.util.List;

/**
 * @author MissChen
 * @date 2024年04月01日 9:00
 */
public class ProductServiceProxy implements ProductService {
    private TransactionManager tran= (TransactionManager) ObjectFactory.getObject("tran");
    private ProductService productService= (ProductService) ObjectFactory.getObject("productServiceTarget");
    @Override
    public List<Product> findAll() {
        try {
            tran.begin();
            List<Product> products=productService.findAll();
            tran.commit();
            return products;
        } catch (Exception e) {
            tran.rollback();
            throw  e;
        }
    }

    @Override
    public PageInfo<Product> findPage(int pageNo, int pageSize) {
        try {
            tran.begin();
            PageInfo<Product> productPageInfo=productService.findPage(pageNo,pageSize);
            tran.commit();
            return productPageInfo;
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }
}
